Page({
  data: {
    userInfo: null,
    background: [{
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun1.jpg?sign=8e71d97d3a1a08e65dd7b4ad9984c989&t=1739176552', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun1.1.png?sign=932011c2eea6d2fb9f47d7e8a8e3c7b9&t=1739176535' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun7.jpg?sign=73446140c3c27cbddf1c1612c602e37a&t=1739176593', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun7.7.png?sign=71b7f987cee20318c2b4ab218cc0e14b&t=1739176581' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun2.jpg?sign=3df9fe3fa887758f4ad745bd09f838fd&t=1739176616', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun2.2.png?sign=90bbfb1fb434b3484b13765596591efd&t=1739176605' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun3.jpg?sign=2085bf1d06bad9d7ff4cbb3b7813d531&t=1739176640', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun3.3.png?sign=c56f02bbc681b468c6afe8de35040f0a&t=1739176630' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun4.jpg?sign=88f57b28eae34b6cd38e69c08befad80&t=1739176666', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun4.4.png?sign=21cc2707c64c4e02ea9baf398dd74e66&t=1739176652' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun5.jpg?sign=552a24ac25f95383244dd1e28051af3b&t=1739176686', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun5.5.png?sign=e1d4e25d27ca9bab96cef8a7d3a5894f&t=1739176675' // 内容图
      },
      {
        bgImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun6.jpg?sign=e5a79cf134b7d010aa861ec12ad35284&t=1739176698', // 背景图
        contentImage: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/lun/lun6.6.png?sign=fdc967bbbfa2927e68ea564a1ffa9028&t=1739176710' // 内容图
      },
    ],
    indicatorDots: false, //导航点
    vertical: false,
    autoplay: true, //自动轮播
    circular: true, //无缝
    interval: 2000, //间隔时间
    duration: 500, //动画
    previousMargin: 0,
    nextMargin: 0,
    active: 0,
    icon: {},
  },

  // 页面加载时的逻辑
  onLoad() {
    this.updateData();
    console.log('11111111111111111111');

  },
  updateData() {
    const openidRandom = wx.getStorageSync('openidRandom');
    console.log('openidRandom123', openidRandom);
    if (openidRandom) {
      const db = wx.cloud.database();
      const usersCollection = db.collection('users'); // 获取 'users' 集合
      usersCollection.doc(openidRandom).get({
        success: (res) => {
          if (res.data && res.data.userInfo) {
            this.setData({
              userInfo: res.data.userInfo,
            });
          } else {
            console.error('未找到该用户的信息');
          }
        },
        fail: (err) => {
          console.error('查询用户信息失败:', err);
        }
      });
    } else {
      console.error('未找到 openidRandom');
      this.setData({
        userInfo: {
          avatarUrl: 'https://6465-dev-6gwl5et4f0c95997-1336623530.tcb.qcloud.la/home/be56b99a94d3fef97f.jpg?sign=e4e8f0a0b33ec67084a0e8aedba894d6&t=1739176774',
          nickName: '整耶耶用户'
        }
      })
    }
  },

  navigateToPage() {
    wx.switchTab({
      url: '/pages/diandan/diandan', // 确保这里是字符串路径
      success: () => {
        console.log("跳转成功");
      },
      fail: (err) => {
        console.error("跳转失败", err);
      },
    });
  },

  Member() {
    wx.navigateTo({
      url: '/pages/Member/Member', // 确保这里是字符串路径
      success: () => {
        console.log("跳转成功");
      },
      fail: (err) => {
        console.error("跳转失败", err);
      },
    });
  },

  Pointsstore() {
    wx.navigateTo({
      url: '/pages/Pointsstore/Pointsstore', // 确保这里是字符串路径
      success: () => {
        console.log("跳转成功");
      },
      fail: (err) => {
        console.error("跳转失败", err);
      },
    });
  },

  Enterprise() {
    wx.navigateTo({
      url: '/pages/Enterprise/Enterprise', // 确保这里是字符串路径
      success: () => {
        console.log("跳转成功");
      },
      fail: (err) => {
        console.error("跳转失败", err);
      },
    });
  },

  onShow() {
    this.updateData();
    // 121212
    console.log('22222222222222222');
    // 模拟延迟添加 fade-in 类，控制动画触发
    setTimeout(() => {
      this.setData({
        'background[0].fadeClass': 'fade-in',
        'background[1].fadeClass': 'fade-in'
      });
    }, 500); // 延迟 0.5 秒后渐入
  },
  onChange(event) {
    this.setData({
      active: event.detail
    });
  },
  changeProperty: function (e) {
    var propertyName = e.currentTarget.dataset.propertyName
    var newData = {}
    newData[propertyName] = e.detail.value
    this.setData(newData)
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  changeCircular: function (e) {
    this.setData({
      circular: !this.data.circular
    })
  },
  changeVertical: function (e) {
    this.setData({
      vertical: !this.data.vertical
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  }
});